package com.hns.can.report.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.service.TendencyChartsDataTools;
import com.hns.can.report.entity.BiDriverIdxInfoEntity;
import com.hns.can.report.service.DrvAnaService;
import com.hns.can.report.vo.DrvAnaDrvVo;
import com.hns.frame.mybatis.Pagination;

/**
 * 驾驶员画像控制类
 * 
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/drvAna")
public class DrvAnaController extends BaseController {
    /**
     * 驾驶员画像service
     */
    @Autowired
    private DrvAnaService drvAnaService;
    @Autowired
    private TendencyChartsDataTools tendencyChartsDataTools;
    
    /**
     * 获取驾驶员信息
     * 
     * @param drvId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvInfo")
    @ResponseBody
    public Object getCarInfoByCarId(@RequestParam(value = "drvId") String drvId) throws Exception {
        List<BaseEntity> entity = drvAnaService.getDrvAnaDrvInfo(drvId);
        return this.getReturnResult(entity);
    }
    
    /**
     * 车辆列表
     * 
     * @param lineId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getRelatedCarPage")
    @ResponseBody
    public Object getRelatedCarPage(DrvAnaDrvVo vo) throws Exception {
        Pagination page = drvAnaService.getRelatedCarPage(vo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 能耗—总能耗 百公里能耗 排名
     * 
     * @param carId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvEnerIdxInfo")
    @ResponseBody
    public Object getDrvEnerIdxInfo(DrvAnaDrvVo vo) throws Exception {
	    vo.setIdxTypeArr(new String[]{"060401","060402","060403","060404","060405","060406","060407","060408","060409"});
    	List<BiDriverIdxInfoEntity>  list= drvAnaService.getDrvIdxInfo(vo);
    	return this.getReturnResult(list);
    	
    }
    
    /**
     * 能耗—趋势
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/geDrvEnerTrendInfo")
    @ResponseBody
    public Object geDrvEnerTrendInfo(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060501","060502","060601"});
        List<Map<String,Object>> list = drvAnaService.getDrvTrendInfo(vo);
        list = tendencyChartsDataTools.fillMultiTendencyData(list, vo.getDateType());
        return this.getReturnResult(list);
    }
    
    /**
     * 能耗排名
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvEnerRankInfo")
    @ResponseBody
    public Object getDrvEnerRankInfo(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060701","060702","060703"});
        List<Map<String,Object>> list = drvAnaService.getDrvEnerRankInfo(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 查询行为数据
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvBehIdxInfo")
    @ResponseBody
    public Object getDrvBehIdxInfo(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060101","060102"});
        List<BiDriverIdxInfoEntity> list = drvAnaService.getDrvIdxInfo(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 查询行为趋势
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvAnaBehIdx")
    @ResponseBody
    public Object getDrvAnaBehIdx(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060201","060202","060203","060204","060205","060206","060207","060208","060209","060210","060211","060212","060213","060214","060299"});
        List<Map<String,Object>> list = drvAnaService.getDrvTrendInfo(vo);
        list = tendencyChartsDataTools.fillMultiTendencyData(list, vo.getDateType());
        return this.getReturnResult(list);
    }
    
    /**
     * 行为排名
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvBehRankInfo")
    @ResponseBody
    public Object getDrvBehRankInfo(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060301"});
        List<Map<String,Object>> list = drvAnaService.getDrvBehRankInfo(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 不良驾驶行为排名
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvUnBehRankInfo")
    @ResponseBody
    public Object getDrvUnBehRankInfo(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"050601","050602","050603","050604","050605","050606","050607","050608","050609","050610","050611","050612","050613","050614","050699"});
        List<Map<String,Object>> list = drvAnaService.getDrvAnaRank(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 行为排名
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvFaultRankInfo")
    @ResponseBody
    public Object getDrvFaultRankInfo(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"051001"});
        List<Map<String,Object>> list = drvAnaService.getDrvAnaRank(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 能耗转速分析
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvEnergySpdAna")
    @ResponseBody
    public Object getDrvEnergySpdAna(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060801","060802","060803"});
        List<Map<String,Object>> list = drvAnaService.getDrvEnergySpdAna(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 查询工作趋势
     * 
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getWorkDura")
    @ResponseBody
    public Object getWorkDura(DrvAnaDrvVo vo) throws Exception {
        vo.setIdxTypeArr(new String[]{"060901","060902"});
        List<Map<String,Object>> list = drvAnaService.getDrvTrendInfo(vo);
        list = tendencyChartsDataTools.fillMultiTendencyData(list, vo.getDateType());
        return this.getReturnResult(list);
    }
    
    /**
     * 考勤明细
     * 
     * @param  
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDrvAttnPage")
    @ResponseBody
    public Object getDrvAttnPage(DrvAnaDrvVo vo) throws Exception {
        if("02".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate-7,'yyyy-mm-dd')BEGIN_ATTN_TIME,to_char(sysdate,'yyyy-mm-dd')END_ATTN_TIME ");
        }else if("03".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate-7,'yyyy-mm-dd')BEGIN_ATTN_TIME,to_char(sysdate-1,'yyyy-mm-dd')END_ATTN_TIME ");
        }else if("04".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate,'yyyy-mm')||'-01'BEGIN_ATTN_TIME,to_char(sysdate-1,'yyyy-mm-dd')END_ATTN_TIME ");
        }else if("05".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(add_months(sysdate,-1),'yyyy-mm')||'-01'BEGIN_ATTN_TIME,to_char(add_months(sysdate,-1),'yyyy-mm')||'-31'END_ATTN_TIME ");
        }else if("06".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate,'yyyy')||'-01-01'BEGIN_ATTN_TIME,to_char(sysdate-1,'yyyy-mm-dd')END_ATTN_TIME");
        }else if("07".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(add_months(sysdate,-12),'yyyy')||'-01-01'BEGIN_ATTN_TIME,to_char(add_months(sysdate,-12),'yyyy')||'-12-31'END_ATTN_TIME ");
        }
        DrvAnaDrvVo timeVo = drvAnaService.getAttnTime(vo);
        timeVo.setDrvId(vo.getDrvId());
        Pagination page = drvAnaService.getDrvAttnPage(timeVo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 获取时间
     * 
     * @param  
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getTimeVo")
    @ResponseBody
    public Object getTimeVo(DrvAnaDrvVo vo) throws Exception{
      //02.昨天 03.近7天 04.本月 05.上月 06.今年 07.去年
        if("02".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate-7,'yyyy-mm-dd')BEGIN_ATTN_TIME,to_char(sysdate,'yyyy-mm-dd')END_ATTN_TIME ");
        }else if("03".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate-7,'yyyy-mm-dd')BEGIN_ATTN_TIME,to_char(sysdate-1,'yyyy-mm-dd')END_ATTN_TIME ");
        }else if("04".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate,'yyyy-mm')||'-01'BEGIN_ATTN_TIME,to_char(sysdate-1,'yyyy-mm-dd')END_ATTN_TIME ");
        }else if("05".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(add_months(sysdate,-1),'yyyy-mm')||'-01'BEGIN_ATTN_TIME,to_char(add_months(sysdate,-1),'yyyy-mm')||'-31'END_ATTN_TIME ");
        }else if("06".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(sysdate,'yyyy')||'-01-01'BEGIN_ATTN_TIME,to_char(sysdate-1,'yyyy-mm-dd')END_ATTN_TIME");
        }else if("07".equals(vo.getDateType())){
            vo.setTmpDateStr("to_char(add_months(sysdate,-12),'yyyy')||'-01-01'BEGIN_ATTN_TIME,to_char(add_months(sysdate,-12),'yyyy')||'-12-31'END_ATTN_TIME ");
        }
        DrvAnaDrvVo timeVo = drvAnaService.getAttnTime(vo);
        return this.getReturnResult(timeVo);
    }
    
}
